﻿using System.Net;
using System.Net.Mail;
using System.Text;

namespace Common
{
    public class MailHelper
    {
        public void SendMail(object dto1)
        {
            var dto = dto1 as MailDto;
            var msg = new MailMessage();
            foreach (string sendMail in dto.SendMail)
            {
                msg.To.Add(sendMail);
            }

            msg.From = new MailAddress("maomao20012@163.com", "亚洲流体网", Encoding.UTF8);
            msg.Subject = dto.MailTitle; //邮件标题            
            msg.SubjectEncoding = Encoding.UTF8; //邮件标题编码
            msg.Body = dto.MailContent; //邮件内容
            msg.BodyEncoding = Encoding.UTF8; //邮件内容编码
            msg.IsBodyHtml = true; //是否是HTML邮件
            msg.Priority = MailPriority.Normal; //邮件优先级

            var client = new SmtpClient
                             {
                                 Credentials = new NetworkCredential("maomao20012@163.com", "happycat83"),
                                 Port = 25,
                                 Host = "smtp.163.com",
                                 EnableSsl = false
                             };
            //上述写你的GMail邮箱和密码
            //object userState = msg;
            try
            {
                client.Send(msg);
            }
            catch (SmtpException ex)
            {
                Log.LogHandler.LogError(ex.Message);
                Log.LogHandler.LogError("Common.MailHelper.SendMail", ex);
            }
        }
    }

    public class MailDto
    {
        public string[] SendMail { get; set; }

        public string MailTitle { get; set; }

        public string MailContent { get; set; }
    }
}